<template>
  <!-- 最近联系人 -->
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span>{{ t('personalHomepage.m20') }}</span>
      </div>
    </template>
    <ul class="recent-contact">
      <li
        class="recent-contact-item"
        v-for="(item, index) in recentContactsList"
        :key="index"
        @click="handelSendMsg(item)"
      >
        <div class="avatar">
          <img :src="item.avatar" />
        </div>
        <div class="info flexsc">
          <h4 class="line-1">{{ item.userName }}</h4>
          <!-- <p>{{ item.remark }}</p> -->
        </div>
      </li>
    </ul>
  </el-card>
</template>

<script setup>
import { ref, reactive, onBeforeMount, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { getRecentContacts } from '@/service/personalHomepage'
import { useI18n } from 'vue-i18n'

import useDialogue from '@/stores/dialogue'

const router = useRouter()
const route = useRoute()
const { t, locale } = useI18n()

onBeforeMount(() => {
  init()
})
watch(locale, () => {
  init()
})

//
const recentContactsList = ref([])
const getRecentContactsFn = () => {
  getRecentContacts().then((res) => {
    recentContactsList.value = res.data
  })
}

const storeDialogue = useDialogue()
const { setDialogVisible, setActivePerson } = storeDialogue

// 发消息
const handelSendMsg = ({ userName, id }) => {
  setDialogVisible(true)
  setActivePerson({
    customerName: userName,
    customerId: id
  })
}

const init = () => {
  getRecentContactsFn()
}
</script>

<style scoped lang="scss">
.box-card {
  min-height: 660px;
}
:deep(.el-card__body) {
  padding-left: 0;
}
.recent-contact {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, calc(100% / 3 - 20px));
  gap: 20px;

  .recent-contact-item {
    width: 100%;
    padding: 20px;
    box-shadow: 0px 0px 10px 0px rgba(171, 167, 195, 0.2);
    cursor: pointer;
    border-radius: 6px;
    display: grid;
    grid-template-columns: 50px 200px;
    gap: 20px;

    .avatar {
      width: 50px;
      height: 50px;

      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
      }
    }

    .info {
      // padding-top: 10px;

      h4 {
        font-size: 18px;
        font-weight: 600;
        color: #252628;
        line-height: 30px;
      }

      // p {
      //   font-family: Source Han Sans CN;
      //   font-weight: 400;
      //   color: #9d9fa5;
      //   font-size: 16px;
      // }
    }
  }
}
</style>
